﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CRM.Database.Model.Customers>" %>


<%@ Import Namespace="CRM.Database.Model" %>
<%@ Import Namespace="CRM.Resourses" %>


<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdBonuses";
                                        settings.KeyFieldName = "IdBonus";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Contracts", Action = "CustomerBonusPartialEdit", customerId = Model.IdCustomer };
                                        settings.SettingsPager.PageSize = 20;

                                       

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.RegistrationDate;
                                            column.FieldName = "RegistrationDate";
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.LegalEntityName;
                                            column.FieldName = "IdLegalEntity";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {

                                                comboBoxProperties.DataSource = Model.LegalEntities;
                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "IdLegalEntity";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                      

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.DistributorAndProduct;
                                            column.FieldName = "IdPriceCondition";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new PriceConditionsCollection();
                                                comboBoxProperties.DataSource = col.GetList();
                                                comboBoxProperties.TextField = "PriceCondition";
                                                comboBoxProperties.ValueField = "IdPriceCondition";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Value;
                                            column.FieldName = "Value";
                                        });


                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Basement;
                                            column.FieldName = "Basement";
                                            column.ColumnType = MVCxGridViewColumnType.Memo;
                                        });

                                       
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.BonusType;
                                            column.FieldName = "IdBonusType";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new BonusTypesCollection();
                                                comboBoxProperties.DataSource = col.GetList();
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdBonusType";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Amount;
                                            column.FieldName = "Amount";

                                        });

                                      

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.BonusStatus;
                                            column.FieldName = "IdBonusStatus";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new BonusesStatusesCollection();
                                                comboBoxProperties.DataSource = col.GetList();
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdBonusStatuses";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.SigningDate;
                                            column.FieldName = "SigningDate";
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.ClosingDate;
                                            column.FieldName = "ClosingDate";
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                        });


                                       

                                       

                                        
                                       // Добавление редактирования
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Contracts", Action = "CustomerBonusPartialUpdate", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Contracts", Action = "CustomerBonusPartialAdd", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Contracts", Action = "CustomerBonusPartialDelete", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                      //  settings.Width = Unit.Percentage(100);
                                    }).Bind(Model.Bonuses).GetHtml();
                                    
                                    
                                    %>